// This is a custom client-side implementation example of Backfire.
function startBackfireExample() {
  
  // Create my custom backfireOptions object.
  var backfireOptions = {
    
    // Give it the url to save to, cross-domain allowed.
    url: "/Save.aspx",
    
    // Optionally do an initial check if saving to that url is allowed.
    verifyAccessOnLoad: true,
    
    // Handle incoming messages from the server.
    messageHandler: function(message) {
      switch (message) {

        // With verifyAccessOnLoad enabled, AccessGranted is returned when all is okay.
        // This allows you to show a button or toolbar if you like.
        case "AccessGranted":
          // Let's create a simple button that calls Backfire.save() when pressed.
          var button = document.createElement("button");
          button.innerHTML = "Backfire!";
          button.setAttribute("style", "position: fixed; left: 20px; top: 100px;")
          button.onclick = function() { Backfire.save(); }
          document.body.appendChild(button);
          break;

        // With verifyAccessOnLoad enabled, AccessDenied is returned if the server is set up 
        // correctly, but you don't have access to save changes.
        case "AccessDenied":
          alert("Access was denied!");
          break;
        
        // After saving went okay, refresh Backfire to clean up its collection of changes.
        case "SaveSuccessful":
          Backfire.refresh();
          alert("Your changes have been saved.");
          break;
          
        // When saving failed, show it.
        case "SaveFailed":
          alert("Saving failed.");
          break;
      }
    }
  };

  // Go
  Backfire.load(backfireOptions);
}